//
//  NextVC.swift
//  XJUIKit_Example
//
//  Created by shanlin on 2017/11/20.
//  Copyright © 2017年 CocoaPods. All rights reserved.
//

import UIKit
import XJUIKit
import XJExtension

class NextVC: UIViewController {

    fileprivate lazy var textView: XJTextView = {
        let style = XJTextViewStyle()
        let textView = XJTextView(frame: CGRect.zero, textContainer: nil, style: style)
        return textView
    }()
    
    fileprivate lazy var label: UILabel = UILabel()
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        navigationItem.title = "SLTextView全新整合"
        
        view.addSubview(textView)
        textView.frame = CGRect(x: 20, y: 100, width: UIScreen.main.bounds.width - 40, height: 300)
        textView.backgroundColor = UIColor(white: 244/255, alpha: 1.0)
        textView.textCallBack = { [weak self] (textView, textNumber, isHasText) in
            print("textNumber=\(textNumber), 是否有文字:=\(isHasText)------文字长度：\(textView.text.count)")
            self?.label.text = textNumber
            self?.label.sizeToFit()
            self?.label.frame = CGRect(x: textView.frame.maxX - (self?.label.bounds.width ?? 0), y: textView.frame.maxY, width: self?.label.bounds.width ?? 0, height: self?.label.bounds.height ?? 0)
        }
    
        view.addSubview(label)
        label.sizeToFit()
        label.frame = CGRect(x: textView.frame.maxX - label.bounds.width, y: textView.frame.maxY, width: label.bounds.width, height: label.bounds.height)
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "TextField", style: .plain, target: self, action: #selector(rightClick))
    }

    @objc fileprivate func rightClick() {
        let textFiledVC = VC2()
        navigationController?.pushViewController(textFiledVC, animated: true)
    }

}

